/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#include "stdafx.h"
#include <pgl/core/PGLViewScreen.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
PGL_IMPLEMENT_DYNCREATE(CPGLViewScreen, CObject);
 

void CPGLViewScreen::SerializeXML(CPGLArchive& ar)
{
	static const TCHAR szTag[] = _T("CPGLViewScreen");


	markup::CMarkupArchive& xml = *((markup::CMarkupArchive*)ar.GetMarkup());

	if(ar.IsStoring())
	{
		xml.AddChildElem(szTag);
		xml.IntoElem();

			xml.AddChildElemEx(_T("Height"), m_iHeight);
			xml.AddChildElemEx(_T("Width"), m_iWidth);
			xml.AddChildElemEx(_T("Tx"), m_iTx);
			xml.AddChildElemEx(_T("Ty"), m_iTy);
		xml.OutOfElem();
	}
	else
	{
		if  (!xml.FindChildElem(szTag))
				return;

		xml.IntoElem();

			xml.FindGetChildData(_T("Height"), m_iHeight);
			xml.FindGetChildData(_T("Width"), m_iWidth);
			xml.FindGetChildData(_T("Tx"), m_iTx);
			xml.FindGetChildData(_T("Ty"), m_iTy);

		xml.OutOfElem();
	}
}

#ifdef _DEBUG
void CPGLViewScreen::Dump( CDumpContext& dc ) const
{
    // call base class function first
    CObject::Dump( dc );

    // now do the stuff for our specific class
	// now dumping
	dc <<_T("--- CPGLViewScreen ---") << "\n";
}

void CPGLViewScreen::AssertValid() const
{
    // call inherited AssertValid first
    CObject::AssertValid();

    // check CPGLViewScreen members...
	ASSERT(m_iTx>=0);
	ASSERT(m_iTy>=0);
	ASSERT(m_iWidth>0);
	ASSERT(m_iHeight>0);
} 

#endif

CPGLViewScreen::CPGLViewScreen(int _iTx,int _iTy,int _iWidth,int _iHeight)
{	
	m_iTx=_iTx; 
	m_iTy=_iTy; 
	m_iWidth=__max(1,_iWidth); 
	m_iHeight=__max(1,_iHeight); 
};	
	
CPGLViewScreen& CPGLViewScreen::operator= (const CPGLViewScreen& v)
{
	if (this!=&v)
	{
		m_iTx=v.m_iTx; 
		m_iTy=v.m_iTy; 
		m_iWidth=v.m_iWidth; 
		m_iHeight=v.m_iHeight; 
	}
	return *this;
}

void CPGLViewScreen::PlotGfx(gfxinterface::CGfxInterface& gfx)
{
	gfx.SetBoundingBox(m_iTx, m_iTy,m_iTx+m_iWidth,m_iTy+m_iHeight);
}
